from time import time


class First():
    class Example():
        def __enter__(self):
            print('打开了')
            return 'enter 返回值'

        def __exit__(self, exc_type, exc_val, exc_tb):
            print('关闭了')
            print(exc_type)
            print(exc_val)
            print(exc_tb)
            pass

    with Example() as tmp:
        print(tmp)

    print(50 * '=')

class Second():
    '''
        说明： + 可以产生新的数列，而 += 不会产生新的数列 
    '''
    def a():
        a = [1, 2, 3]
        b = a 
        a = a + [4, 5, 6]

        print(f'a = {a}')
        print(f'b = {b}')

    def b():
        a = [1, 2, 3]
        b = a 
        a += [4, 5, 6]

        print(f'a = {a}')
        print(f'b = {b}')

    a()
    print(50 * '-')
    b()
    print(50 * '=')
    
class Third():
    def time_consume(func):
        def inner():
            start = time()
            result = func()
            end = time()
            print(end-start)
            return result 
        return inner
    
    @time_consume
    def normal_for():
        a = []
        for i in range(100_0000):
            a.append(i)
        # print(a)

    @time_consume
    def list_derivation():
        a = [i for i in range(100_0000)]
        # print(a)

    normal_for()
    list_derivation()
    print(50 * '=')

class forth():
    a = []
    print(a.__sizeof__()) # 40 个字节
    b = [1,2,3]
    print(b.__sizeof__())
    print(50 * '=')
